﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ShopAdmin/Site.Master" AutoEventWireup="true" CodeBehind="ShopEdit.aspx.cs" Inherits="VK.Casemeet.Web.ShopAdmin.Shops.ShopEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="contentHead" runat="server">
    <script type="text/javascript" src="/Scripts/ajaxupload.js"></script>
    <script type="text/javascript" src="http://ditu.google.cn/maps/api/js?v=3.7&sensor=false&language=cn"></script> 
    <script type="text/javascript">
        var geocoder;
        var gMap;
        //google.load("maps", "2", { "base_domain": "ditu.google.cn" }); 
        function searchAddress() {
            var address = document.getElementById("address").value;
            geocoder.geocode({ 'address': address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }
    </script>
    <script type="text/javascript">
        $("document").ready(function () {
            if (<% =area1 %> == 0) {
                BindArea(0, "#ddlArea1", 0, 0, 0);
            } else {
                BindArea(0, "#ddlArea1", <% =area1 %>, <% =area2 %>, <% =area3 %>);
            }
        });

        function BindArea(parentID, ddlControl, area1, area2, area3) {
            $.ajax({
                type: "post",
                url: "/Admin/CommService.asmx/GetArea",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: "{ \"parentID\":" + parentID + " }",
                beforeSend: function (jsonHttpRequest) {
                    this;
                },
                success: function (jsonHttpRequest, textStatus) {
                    var temp_option = new String;
                    temp_option += "<option value=\"0\">请选择</option>";
                    if (ddlControl == "#ddlArea1") { temp_option = fillOption(temp_option, jsonHttpRequest, area1); }
                    if (ddlControl == "#ddlArea2" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area2); }
                    if (ddlControl == "#ddlArea3" && parentID != "0") { temp_option = fillOption(temp_option, jsonHttpRequest, area3); }
                    $(ddlControl).html(temp_option);
                    if (ddlControl == "#ddlArea1") {
                        BindArea($(ddlControl).val(), "#ddlArea2", area1, area2, area3);
                    }
                    if (ddlControl == "#ddlArea2") {
                        BindArea($(ddlControl).val(), "#ddlArea3", area1, area2, area3);
                    }
                },
                error: function (jsonHttpRequest, textStatus, errorThrown) {
                    this;
                },
                complete: function (jsonHttpRequest, textStatus) {
                    this;
                }
            });
        }
        function area1_onchange() {
            if ($("#ddlArea1").val() != "0") {
                $("#ddlArea2").html("");
                $("#hidArea").val($("#ddlArea1")[0].options[$("#ddlArea1")[0].selectedIndex].text);
                BindArea($("#ddlArea1").val(), "#ddlArea2", 0, 0, 0);
            }
        }
        function area2_onchange() {
            if ($("#ddlArea2").val() != "0") {
                $("#ddlArea3").html("");
                $("#hidArea").val($("#ddlArea1")[0].options[$("#ddlArea1")[0].selectedIndex].text + " " + $("#ddlArea2")[0].options[$("#ddlArea2")[0].selectedIndex].text);
                BindArea($("#ddlArea2").val(), "#ddlArea3", 0, 0, 0);
            }
        }
        function area3_onchange() {
            if ($("#ddlArea3").val() != "0") {
                $("#hidArea").val($("#ddlArea1")[0].options[$("#ddlArea1")[0].selectedIndex].text + " " + $("#ddlArea2")[0].options[$("#ddlArea2")[0].selectedIndex].text + " " + $("#ddlArea3")[0].options[$("#ddlArea3")[0].selectedIndex].text);
            }
        }
        function fillOption(temp_option, jsonHttpRequest, area) {
            $.each(jsonHttpRequest.d, function (i, field) {
                if (area == field.AreaID) {
                    temp_option += "<option selected value=\"" + field.AreaID + "\">" + field.Name + "</option>";
                } else {
                    temp_option += "<option value=\"" + field.AreaID + "\">" + field.Name + "</option>";
                }
            });
            return temp_option;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
    <div class="bodyContent divBody">
        <div class="divDetailOper">
            <asp:LinkButton ID="butSave" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return validator.form();">保存信息</asp:LinkButton>
        </div>
        <div class="divEdit" style="width:98%;margin:10px 0 0 1%;_margin:10px 0 0 0.5%;height:auto;">
            <div class="title">基本信息</div>
            <div class="content">
                <table cellpadding="0" cellspacing="0" class="tableLeftEdit">
                    <tbody>
                        <tr>
                            <th>类型：</th>
                            <td><asp:DropDownList ID="ddlType" runat="server" CssClass="selectddl {min:1, messages:{min:'请选择一项'}}" Width="80%"></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <th>名称：</th>
                            <td><asp:TextBox ID="txtName" runat="server" CssClass="inputText required" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>企业标志：</th>
                            <td>
                                <input id="hidLogoUrl" name="hidLogoUrl" type="hidden" value='<% =logoUrl %>' />
                                <div><a href="#" id="butLogoUrl" class="flb hg30" style="color:#1d3d83;">【点我上传图片】</a><span class="padlef20" style="color:Red;"></span></div>
                                <script type="text/javascript">
                                    $(document).ready(function () {
                                        var button = $('#butLogoUrl'), interval;
                                        new AjaxUpload(button, {
                                            action: '',
                                            onSubmit: function (file, ext) {
                                                if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                                    alert('错误:图片格式不正确!');
                                                    return false;
                                                }
                                                this._settings.action = '/PageHandler/UpLoadFile.ashx?folderName=Logos/';
                                                this._settings.data = { oldFileName: $('#divLogoUrl img').attr('src') };
                                                this.disable();
                                                var tips = $("#butLogoUrl").next();
                                                tips.html("文件上传中请等待");
                                                interval = window.setInterval(function () {
                                                    if (tips.html().length < 20) {
                                                        tips.html(tips.html() + ">");
                                                    } else {
                                                        tips.html('文件上传中请等待');
                                                    }
                                                }, 300);
                                            },
                                            onComplete: function (file, response) {
                                                $("#butLogoUrl").next().html('');
                                                window.clearInterval(interval);
                                                this.enable();
                                                window.clearInterval(interval);
                                                var jsondata = JSON.parse(response);
                                                if (jsondata.Error.length == 0) {
                                                    $("#divLogoUrl").html("");
                                                    $("#divLogoUrl").append("<img alt='' src='/UserImages/Logos/" + jsondata.FileName + "' style='width:188px;height:85px;border:1px solid #bdbcbd;padding:3px;'/>");
                                                    $("#hidLogoUrl").val(jsondata.FileName);
                                                } else {
                                                    alert(jsondata.Error);
                                                }
                                            }
                                        });
                                    });
                                </script>
                                <div id="divLogoUrl"><img alt='' src='/UserImages/Logos/<% =logoUrl %>' style="width:188px;height:85px;border:1px solid #bdbcbd;padding:3px;" /></div>
                            </td>
                        </tr>
                        <tr>
                            <th>联系人：</th>
                            <td><asp:TextBox ID="txtContact" runat="server" CssClass="inputText required" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>联系电话：</th>
                            <td><asp:TextBox ID="txtTelephone" runat="server" CssClass="inputText" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>联系QQ：</th>
                            <td>
                                <asp:TextBox ID="txtQQ" runat="server" CssClass="inputText required number" Width="80%"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <th>电子邮箱：</th>
                            <td><asp:TextBox ID="txtEmail" runat="server" CssClass="inputText" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>网站地址：</th>
                            <td>
                                <asp:TextBox ID="txtSiteUrl" runat="server" CssClass="inputText" Width="80%"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <th>注册资本：</th>
                            <td><asp:TextBox ID="txtCapital" runat="server" CssClass="inputText digits" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>地区：</th>
                            <td>
                                <select id="ddlArea1" name="ddlArea1" onchange="area1_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlArea2" name="ddlArea2" onchange="area2_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
		                        <select id="ddlArea3" name="ddlArea3" onchange="area3_onchange();" class="selectddl {min:1, messages:{min:'请选择一项'}}" style="width:auto;"></select>
                            </td>
                        </tr>
                        <tr>
                            <th>地址：</th>
                            <td><asp:TextBox ID="txtAddress" runat="server" CssClass="inputText" Width="80%"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>店铺公告：</th>
                            <td><asp:TextBox ID="txtNotice" runat="server" CssClass="inputText" Width="80%" TextMode="MultiLine" Height="60px"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>营业执照：</th>
                            <td>
                                <input id="hidImgUrl" name="hidImgUrl" type="hidden" value='<% =imgUrl %>' />
                                <div><a href="#" id="butImgUrl" class="flb hg30" style="color:#1d3d83;">【点我上传图片】</a><span class="padlef20" style="color:Red;"></span></div>
                                <script type="text/javascript">
                                    $(document).ready(function () {
                                        var button = $('#butImgUrl'), interval;
                                        new AjaxUpload(button, {
                                            action: '',
                                            onSubmit: function (file, ext) {
                                                if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                                    alert('错误:图片格式不正确!');
                                                    return false;
                                                }
                                                this._settings.action = '/PageHandler/UpLoadFile.ashx?folderName=Photos/';
                                                this._settings.data = { oldFileName: $('#divImgUrl img').attr('src') };
                                                this.disable();
                                                var tips = $("#butImgUrl").next();
                                                tips.html("文件上传中请等待");
                                                interval = window.setInterval(function () {
                                                    if (tips.html().length < 20) {
                                                        tips.html(tips.html() + ">");
                                                    } else {
                                                        tips.html('文件上传中请等待');
                                                    }
                                                }, 300);
                                            },
                                            onComplete: function (file, response) {
                                                $("#butImgUrl").next().html('');
                                                window.clearInterval(interval);
                                                this.enable();
                                                window.clearInterval(interval);
                                                var jsondata = JSON.parse(response);
                                                if (jsondata.Error.length == 0) {
                                                    $("#divImgUrl").html("");
                                                    $("#divImgUrl").append("<img alt='' src='/UserImages/Photos/" + jsondata.FileName + "' style='width:200px;height:130px;border:1px solid #bdbcbd;padding:3px;'/>");
                                                    $("#hidImgUrl").val(jsondata.FileName);
                                                } else {
                                                    alert(jsondata.Error);
                                                }
                                            }
                                        });
                                    });
                                </script>
                                <div id="divImgUrl"><img alt='' src='/UserImages/Photos/<% =imgUrl %>' style="width:200px;height:130px;border:1px solid #bdbcbd;padding:3px;" /></div>
                                <a href="/UserImages/Photos/<% =imgUrl %>" target="_blank">查看大图</a>
                            </td>
                        </tr>
                        <tr>
                            <th>公司介绍：</th>
                            <td><asp:TextBox ID="txtCompany" runat="server" CssClass="inputText" Width="80%" TextMode="MultiLine" Height="60px"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <th>地图坐标：</th>
                            <td>
                                地址：<input id="address" name="address" type="text" class="inputText" style="width:200px;" value='' />
                                <input id="butSearch" type="button" value="搜索" onclick="searchAddress()" />
                                <input id="txtMap" name="txtMap" type="hidden" value='<% =map %>' />
                                <div id="map_canvas" style="width:80%;height:400px"></div>
                                <script type="text/javascript">
                                    function initialize() {
                                        geocoder = new google.maps.Geocoder();
                                        gMap = google.maps,
                                        uuuid = 1,
                                        myLatlng = new gMap.LatLng(<% =map %>),
                                        myOptions = {
                                            zoom: 13,
                                            center: myLatlng,
                                            mapTypeId: gMap.MapTypeId.ROADMAP,
                                            streetViewControl  : false
                                        },
                                        map = new gMap.Map(document.getElementById('map_canvas'), myOptions);

                                        var marker = new gMap.Marker({
                                            position: myLatlng,
                                            map: map,
                                            title: ""
                                        });

                                        gMap.event.addListener(map, 'click', function (event) {
                                            marker.setMap(null);
                                            marker = new gMap.Marker({
                                                position: event.latLng,
                                                map: map,
                                                title: ''
                                            });
                                            document.getElementById('txtMap').value = event.latLng.lat() + "," + event.latLng.lng();
                                        });
                                    }
                                    initialize();
                            </script>  
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="clear f0" style="height:10px; width:100%"></div>
        <div class="clear divDetailOper">
            <asp:LinkButton ID="LinkButton1" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return validator.form();">保存信息</asp:LinkButton>
        </div>
        <div class="clear f0" style="height:20px; width:100%"></div>
    </div>
</asp:Content>
